function CreateObjectListFrame()
	objFrame = CreateFrame("Frame");
	objFrame:SetScript("OnUpdate", objFrame_OnUpdate);
end

ccrObjectListTable = {};
vLastObjectListScan = nil
function objFrame_OnUpdate(self, elapsed)
	if vLastObjectListScan == nil
	or (GetTime()-vLastObjectListScan >= ccRS.ObjectListUpdate)
	and UnitIsDeadOrGhost("player") ~= 1
	then
		-- Passive updating of object list
		if (# ccrObjectListTable ~= GetTotalObjects()) then
			UpdateObjectList();
		end
		-- if ccR is running the rotation
		if ccrStart or ccrDebug then
			-- Collect information on any nearby enemies to the player
			objPlayerGetNearbyEnemies()
			objPlayerGetMeleeEnemies()
			-- Collect grouped hostiles around a target
			if ccrValidTarget() then objTargetGetNearbyEnemies() end
			-- Collects friendly npc's into a table
			--objGetNearbyNPC()
		end
		vLastObjectListScan = GetTime()
	end
end

function UpdateObjectList()
	local ObjectList = GetTotalObjects();
	if ObjectList ~= nil then
		ccrObjectListTable = {};
		for i = 1, ObjectList do
			table.insert(ccrObjectListTable, GetObjectListEntry(i))
		end
	end
end

tblPGetNearbyEnemies = {}
vLastPGetNECheck = nil
function objPlayerGetNearbyEnemies(update)
	-- Player:GetNearbyEnemies
	if (vLastPGetNECheck == nil or (GetTime()-vLastPGetNECheck >= 0.10))
	or update
	then
		local x
		if range == nil then range = 40 end;
		tblPGetNearbyEnemies = {}
		for x = 1, # ccrObjectListTable do
			local obj = ccrObjectListTable[x]
			if obj
			and obj:Exists()
			and (obj:GetType() == 3 or obj:GetType() == 4)
			and not obj:IsDead()
			and obj:IsAttackable()
			and obj:GetCreatureInfo() ~= "Critter"
			and obj:GetCreatureInfo() ~= "Wild Pet"
			and obj:GetCreatureInfo() ~= "Totem"
			and obj:GetName() ~= "Dreadspinner Egg"
			and obj:GetName() ~= "Creeper Egg"			
			and obj:GetDistance(Player) <= range
			then
				table.insert(tblPGetNearbyEnemies, obj)
			end
		end
		vLastPGetNECheck = GetTime()
	end
end

tblPGetMeleeEnemies = {}
vLastPGetMECheck = nil
function objPlayerGetMeleeEnemies()
	-- Scan PlayerGetNearbyEnemies and filter to those within melee range
	if vLastPGetMECheck == nil
	or (GetTime()-vLastPGetMECheck >= 0.10)
	then
		local x
		tblPGetMeleeEnemies = {}
		if # tblPGetNearbyEnemies > 0 then
			for x = 1, # tblPGetNearbyEnemies do
				local obj = tblPGetNearbyEnemies[x]
				if obj
				and obj:Exists()
				and not obj:IsDead()
				and obj:GetDistance(Player) <= 8
				then
					table.insert(tblPGetMeleeEnemies, obj)
				end
			end
		end
		vLastPGetMECheck = GetTime()
	end
end


tblTGetNearbyEnemies = {}
vLastTGetNECheck = nil
function objTargetGetNearbyEnemies()
	-- Target:GetNearbyEnemies
	if vLastTGetNECheck == nil
	or (GetTime()-vLastTGetNECheck >= 0.10)
	then
		local x
		if range == nil then range = 40 end;
		tblTGetNearbyEnemies = {}
		for x = 1, # ccrObjectListTable do
			local obj = ccrObjectListTable[x]
			if obj
			and obj:Exists()
			and (obj:GetType() == 3 or obj:GetType() == 4)
			and obj:IsAttackable()
			and obj:GetCreatureInfo() ~= "Critter"
			and not obj:IsDead()
			and obj:GetDistance(Target) <= range
			then
				table.insert(tblTGetNearbyEnemies, obj)
			end
		end
		vLastTGetNECheck = GetTime()
	end
end

tblTGetNearbyNPC = {}
vLastTGetNPCCheck = nil
function objGetNearbyNPC()
	if (vLastTGetNPCCheck == nil or (GetTime()-vLastTGetNPCCheck >= 0.10)) then
		local x
		if range == nil then range = 40 end;
		tblTGetNearbyNPC = {}
		for x = 1, # ccrObjectListTable do
			local obj = ccrObjectListTable[x]
			if obj
			and obj:Exists()	
			and obj:GetType() == 3
			then
				local guid = obj:GetGUID();
				local B = tonumber(guid:sub(5,5), 16);
				local maskedB = B % 8; -- x % 8 has the same effect as x & 0x7 on numbers <= 0xf
				local knownTypes = {[0]="player", [3]="NPC", [4]="pet", [5]="vehicle"};		
				ClearUnitID("NPC_Check")
				obj:SetAsUnitID("NPC_Check")
				if knownTypes[maskedB] == "NPC"
				and not obj:IsDead()
				and not ccrUnitIsAPlayer("NPC_Check")
				and UnitIsFriend("player","NPC_Check")
				and UnitCreatureType("NPC_Check") == "Humanoid"
				and obj:GetDistance(Player) <= range
				then
					table.insert(tblTGetNearbyNPC, obj)
				end
			end
		end
		vLastTGetNPCCheck = GetTime()
	end
end
--[[
	
	Better object list collection

ccR_ObjectList = {}
ccR_Items = {}
ccR_Container = {}
ccR_Objects = {}
ccR_Units = {}
ccR_Players = {}
ccR_GameObjects = {}
ccR_DynamicObject = {}
ccR_Corpse = {}
function ccR_CollectObjectList()
	-- Collect the object list from Firehack
	local tmpObject = GetTotalObjects();
	if tmpObject ~= nil then
		ccR_ObjectList = {};
		for i = 1, tmpObject do
			table.insert(ccR_ObjectList, GetObjectListEntry(i))
		end
	end
	-- Move object type into appropiate table
	if #ccR_ObjectList > 0 then
		--- Clear tables
		ccR_Objects = {}
		ccR_Items = {}
		ccR_Container = {}
		ccR_Units = {}
		ccR_Players = {}
		ccR_GameObjects = {}
		ccR_DynamicObject = {}
		ccR_Corpse = {}
		local x
		for x = 1, #ccR_ObjectList do
			local tmpObject = ccR_ObjectList[x]
			if tmpObject:GetType() == 0 then table.insert(ccR_Objects, tmpObject) end
			if tmpObject:GetType() == 1 then table.insert(ccR_Items, tmpObject) end
			if tmpObject:GetType() == 2 then table.insert(ccR_Container, tmpObject) end
			if tmpObject:GetType() == 3 then table.insert(ccR_Units, tmpObject) end
			if tmpObject:GetType() == 4 then table.insert(ccR_Players, tmpObject) end
			if tmpObject:GetType() == 5 then table.insert(ccR_GameObjects, tmpObject) end
			if tmpObject:GetType() == 6 then table.insert(ccR_DynamicObject, tmpObject) end
			if tmpObject:GetType() == 7 then table.insert(ccR_Corpse, tmpObject) end
		end
	end
end

]]--